﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_AddDimission : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 50)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if(!IsPostBack)
        {
            TarreOA.TarreOAModels.User user = UserManager.FindByUserId(int.Parse(Request.QueryString["uid"]));
            txtLoginName.Text = user.LoginName;
            txtUserName.Text = user.UserName;
            if (user.State)
            {
                lblDimissionTime.Text = "离职时间";
                lblDimissionCause.Text = "离职原因";
            }
            else
            {
                lblDimissionTime.Text = "复职时间";
                lblDimissionCause.Text = "复职原因";
            }
            DateTime dt = System.DateTime.Now;
            txtDimissionTime.Text = dt.ToShortDateString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DimissionInfo dimissionInfo = new DimissionInfo();
        if(txtDimissionTime.Text!=null && txtDimissionTime.Text!="")
        {
            dimissionInfo.DimissionTime = Convert.ToDateTime(txtDimissionTime.Text);
        }
        if (txtDimissionCause.Text != null)
        {
            dimissionInfo.DimissionCause = txtDimissionCause.Text.Trim();
        }
        else 
        {
            dimissionInfo.DimissionCause = "";
        }
        TarreOA.TarreOAModels.User user = new User();
        user.UserId = Convert.ToInt32(Request.QueryString["uid"]);
        dimissionInfo.User = user;
        bool flag = false;
        flag = DimissionInfoManager.AddDimissionInfo(dimissionInfo);
        if (flag)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('操作成功！');</script>");
            Response.Redirect("UserList.aspx?sucess=1");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('操作失败！');</script>");
            Response.Redirect("UserList.aspx?sucess=0");
        }
    }
}
